# import uuid
# import threading
#
# from random import choice
# from rest_framework import viewsets
# from rest_framework.mixins import CreateModelMixin, ListModelMixin, RetrieveModelMixin
#
# from game.models import Record
# from game.serializer import UserSerializer
# from rest_framework.response import Response
#
#
# from rest_framework.views import APIView
#
#
# def fun_timer(self):
#     print('Hello Timer!')
#     global timer
#     timer = threading.Timer(120, self.fun_timer())
#     timer.start()
#
#
# timer = threading.Timer(1, fun_timer)
# timer.start()
#
#
# class SmsCodeViewset(ListModelMixin,CreateModelMixin,RetrieveModelMixin,viewsets.GenericViewSet):
#
#
#
#     serializer_class = UserSerializer
#     queryset = Record.objects.all().order_by("-add_time")
#
#     def generate_code(self):
#
#         seeds = "1234567890"
#         random_str=int(choice(seeds))
#         return random_str
#
#     def create(self, request, *args, **kwargs):
#
#         serializer = self.get_serializer(data=request.data)
#         serializer.is_valid(raise_exception=True)
#         #beton = serializer.validated_data["beton"]
#
#         randomnum = self.generate_code()
#         print(randomnum)
#
#         if randomnum in [0,1,2,3,4]:
#             code_record = Record(num=randomnum,isbig="0")
#             code_record.save()
#
#         else:
#             code_record = Record(num=randomnum, isbig="1")
#             code_record.save()
#
#         return  Response()
#
#



# class AuthView(APIView):
#
#     def post(self,request,*args,**kwargs):
#
#         ret = {'code':1000}
#         user = request.data.get('user')
#         pwd = request.data.get('pwd')
#
#         user = models.UserInfo.objects.filter(user=user,pwd=pwd).first()
#         if not user:
#             ret['code'] = 1001
#             ret['error'] = '用户名或密码错误'
#         else:
#             uid = str(uuid.uuid4())
#             models.UserToken.objects.update_or_create(user=user,defaults={'token':uid})
#             ret['token'] = uid
#         return Response(ret)